package org.wxd.category.spi.impl;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.wxd.category.spi.Category;
import org.wxd.category.spi.CategoryOperations;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @Description:
 * @Author : wangxd
 * @Date: 2015-11-12
 * @Version 1.0
 */
@Repository
public final class CategoryMongoOperations implements CategoryOperations {

    @Resource
    private MongoTemplate mongoOps;


    public Optional<Category> ofId(String id) {
        return Optional.ofNullable(
                mongoOps.findOne(Query.query(Criteria.where("_id").is(id)),Category.class)
        );
    }

    public Optional<Category> ofParentId(String pId) {
        return null;
    }

    public List<Category> list() {
        return null;
    }

    public Category store(Category category) {
        mongoOps.insert(category);
        return category;
    }

    public Category remove(Category category) {
        return null;
    }
}
